package com.cdks.wuxiu.api.service.mysql;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cdks.wuxiu.api.component.constant.Constant;
import com.cdks.wuxiu.api.mapper.UserFansInfoMapper;
import com.cdks.wuxiu.api.model.dto.UserFocusDTO;
import com.cdks.wuxiu.entity.mysql.UserFansInfo;

import java.util.List;
import org.springframework.stereotype.Service;


/**
 * 用户粉丝信息 服务实现类
 */
@Service
public class UserFansInfoServiceImpl extends ServiceImpl<UserFansInfoMapper, UserFansInfo> implements UserFansInfoService {
    @Override
    public int focus(long fansId, long userId) {
        UserFansInfo info  = new UserFansInfo();
        info.setUserId(userId);
        info.setFansId(fansId);

        baseMapper.insert(info);

        return 0;
    }

    @Override
    public int cancel(long fansId, long userId) {
        QueryWrapper<UserFansInfo> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(UserFansInfo::getFansId, fansId)
                        .eq(UserFansInfo::getUserId, userId);
        baseMapper.delete(wrapper);

        return 0;
    }

    @Override
    public List<UserFocusDTO> getList(long userId, long startId) {
        return baseMapper.getList(userId, startId, Constant.LIST_PAGE_SIZE);
    }

    @Override
    public UserFansInfo queryFocusByUser(long userId, long destId) {
        QueryWrapper<UserFansInfo> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(UserFansInfo::getFansId, userId)
                        .eq(UserFansInfo::getUserId, destId);
        
        return baseMapper.selectOne(wrapper);
    }
}
